/* CORBAServer.hh -- Servidor CORBA
 *
 * Copyright (C) 2008, Diogo F. S. Ramos <diogo.ramos@usp.br>
 * GEAR - Grupo de Estudos Avançados em Robótica
 * <http://www.sel.eesc.usp.br/gear>
 *
 * This file is part of GEARMedula.
 * 
 * GEARMedula is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, version 3 of the
 * License.
 * 
 * GEARMedula is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

#ifndef CORBASERVER_HH_
#define CORBASERVER_HH_

#include "GEARMedulaIDL.hh"

#include "Monitor.hh"
#include "Control.hh"
#include "Thread.hh"
#include "XError.hh"

class Visao_impl : public virtual POA_Visao{
    Monitor * monitor_;
public :
    virtual void setField( const float * field ) throw (CORBA::SystemException);
    virtual void setWorld( const float * world ) throw (CORBA::SystemException);
    void setMonitor( Monitor * monitor );
};

class IA_impl : public virtual POA_IA{
    Monitor * monitor_;
    Control * control_;
    XError xerror;
public :
    virtual void SetVel( const CORBA::Short id, const float vx, const float vy, const float va )  throw (CORBA::SystemException);
    virtual void DribbleEnable( const CORBA::Short id, const CORBA::Short enable ) throw (CORBA::SystemException);
    virtual void Kick( const CORBA::Short id, const CORBA::Short nivel ) throw (CORBA::SystemException);
    virtual void getField( float * field ) throw (CORBA::SystemException);
    virtual void getWorld( float * world ) throw (CORBA::SystemException);
    virtual void SayHello( const CORBA::Short id ) throw (CORBA::SystemException);
    void setMonitor( Monitor * monitor );
    void setControl( Control * control );
};

class CORBAServer: public Thread{
    CORBA::ORB_var orb;
    Visao_impl * visao_servant_;
    IA_impl * ia_servant_;
    CORBA::Boolean bindObjectToName(CORBA::ORB_ptr orb, CORBA::Object_ptr objref, CosNaming::Name objectName);
    Monitor * monitor;
    Control * control_;
    XError xerror;

    void Run(void * ptr);
public:
    CORBAServer();
    ~CORBAServer();
    void Init( int argc, char * argv[], Monitor * monitor_ptr, Control * control_ptr );
};
#endif	// CORBASERVER_HH_
